import { IPSSysDBScheme } from '../../database/ipssys-dbscheme';
import { IPSDELogic } from './ipsdelogic';
import { IPSDELogicParam } from './ipsdelogic-param';
import { IPSDERawSqlCallLogic } from './ipsderaw-sql-call-logic';
import { PSDELogicNodeImpl } from './psdelogic-node-impl';

export class PSDERawSqlCallLogicImpl extends PSDELogicNodeImpl implements IPSDERawSqlCallLogic {
  protected dstpsdelogicparam: IPSDELogicParam | null = null;

  getDstPSDELogicParam(): IPSDELogicParam | null {
    if (this.dstpsdelogicparam != null) return this.dstpsdelogicparam;
    const value = this.M.getDstPSDELogicParam;
    if (value == null) {
      return null;
    }
    const ipsdelogic = this.getParentPSModelObject('dataentity.logic.IPSDELogic') as IPSDELogic;
    if (ipsdelogic != null) {
      this.dstpsdelogicparam = ipsdelogic.findPSDELogicParam(value);
    }
    return this.dstpsdelogicparam;
  }

  get dstPSDELogicParam(): IPSDELogicParam | null {
    return this.getDstPSDELogicParam();
  }

  getDstPSDELogicParamMust(): IPSDELogicParam {
    const value = this.getDstPSDELogicParam();
    if (value == null) {
      throw new Error('未指定目标逻辑参数对象');
    }
    return value;
  }

  protected pssysdbscheme: IPSSysDBScheme | null = null;

  getPSSysDBScheme(): IPSSysDBScheme | null {
    if (this.pssysdbscheme != null) return this.pssysdbscheme;
    const value = this.M.getPSSysDBScheme;
    if (value == null) {
      return null;
    }
    this.pssysdbscheme = this.getPSModel4('database.IPSSysDBScheme', value, 'getPSSysDBScheme') as IPSSysDBScheme;
    return this.pssysdbscheme;
  }

  get psSysDBScheme(): IPSSysDBScheme | null {
    return this.getPSSysDBScheme();
  }

  getPSSysDBSchemeMust(): IPSSysDBScheme {
    const value = this.getPSSysDBScheme();
    if (value == null) {
      throw new Error('未指定数据库体系');
    }
    return value;
  }

  get sql(): string {
    return this.M.sql;
  }

  get fillDstLogicParam(): boolean {
    return this.M.fillDstLogicParam != null ? this.M.fillDstLogicParam : false;
  }

  get ignoreResetDstLogicParam(): boolean {
    return this.M.ignoreResetDstLogicParam != null ? this.M.ignoreResetDstLogicParam : true;
  }

  get cls(): string {
    return 'PSDERawSqlCallLogicImpl';
  }

  instanceof(cls: string): boolean {
    if (cls == 'dataentity.logic.IPSDERawSqlCallLogic') return true;
    return super.instanceof(cls);
  }
}
